package no.ntnu.fp.model;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import no.ntnu.fp.utils.XmlParser;

public class Employee extends Entity {
	private String name, address, email, phonenumber;

	public Employee(Element root) {
		super(root);
	}
	
	public Employee(long id, String name, String address, String email, String phoneNumber) {
		super(id);
		this.name = name;
		this.address = address;
		this.email = email;
		this.phonenumber = phoneNumber;
	}

	@Override
	public Element toXml(Document dom) {
		Element rootElement = dom.createElement("employee");
		rootElement.appendChild(XmlParser.createElementWithValue(dom, "id", id + ""));
		rootElement.appendChild(XmlParser.createElementWithValue(dom, "name", name));
		rootElement.appendChild(XmlParser.createElementWithValue(dom, "address", address));
		rootElement.appendChild(XmlParser.createElementWithValue(dom, "phonenumber", phonenumber));
		rootElement.appendChild(XmlParser.createElementWithValue(dom, "email", email));
		return rootElement;
	}

	@Override
	protected void initializeFromXml(Element rootNode) {
		this.name = XmlParser.getTextValue(rootNode, "name");
		this.id = Long.parseLong(XmlParser.getTextValue(rootNode, "id"));
		this.address = XmlParser.getTextValue(rootNode, "address");
		this.email = XmlParser.getTextValue(rootNode, "email");
		this.phonenumber = XmlParser.getTextValue(rootNode, "phonenumber");
	}

	public String getName() {
		return name;
	}

	public String getAddress() {
		return address;
	}

	public String getEmail() {
		return email;
	}

	public String getPhonenumber() {
		return phonenumber;
	}

	@Override
	public String toString() {
		return super.toString() + " " + getName(); 
	}
}
